//
//  ShengJingMessageViewController+LoadData.m
//  JKFuYinProject
//
//  Created by jiukuyinyue on 2017/10/9.
//  Copyright © 2017年 LC. All rights reserved.
//

#import "ShengJingMessageViewController+LoadData.h"
#import <ShareSDK/ShareSDK.h>
#import <ShareSDKUI/ShareSDK+SSUI.h>
#import "JKSongsMessStatus.h"

@implementation ShengJingMessageViewController (LoadData)

//- (void)initLRC:(NSString *)strGC
//{
//    if ([TheHomeManager shareTheHomeManager].shengjPlayBool == 1) {
//        [self.timeArray removeAllObjects];
//        [self.LRCDictionary removeAllObjects];
//        
//        [self.timeArray addObjectsFromArray:[TheHomeManager shareTheHomeManager].timeArr];
//        [self.LRCDictionary setValuesForKeysWithDictionary:[TheHomeManager shareTheHomeManager].dataShengJingLrcDic];
////        [self.geciTableView reloadData];
//        
//        return;
//    }
//    [self.timeArray removeAllObjects];
//    [self.LRCDictionary removeAllObjects];
//    
//    NSString* headerData = strGC;
//    headerData = [headerData stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];  //去除掉首尾的空白字符和换行字符
//    headerData = [headerData stringByReplacingOccurrencesOfString:@"\r" withString:@""];
//    headerData = [headerData stringByReplacingOccurrencesOfString:@"\n" withString:@""];
//    NSString *contentStr2 = headerData;
//    
//    
//    
//    
//    NSString * contentStr = [contentStr2 stringByReplacingOccurrencesOfString:@"<br/>" withString:@""];
//    
//    
//    
//    NSLog(@"%@", contentStr);
//    
//    //歌词为空时的处理
//    if ([contentStr isEqualToString:@""]) {
//        [_geciTableView addSubview:_zanwuLabel];
//        [_geciTableView reloadData];
//        //        _geciTableView.hidden = YES;
//        return;
//    }
//    //2.10 请求歌词为nil的修改
//    if (contentStr == nil) {
//        [_geciTableView addSubview:_zanwuLabel];
//        [_geciTableView reloadData];
//        //        _geciTableView.hidden = YES;
//        return;
//    }
//    
//    [_zanwuLabel removeFromSuperview];
//    _geciTableView.hidden = NO;
//    
//    
//    NSArray * array = [contentStr componentsSeparatedByString:@"["];
//    
//    //    for (NSString * str in array) {
//    //        NSLog(@"%@ ---%zd", str,str.length);
//    //    }
//    
//    //临时记录相同歌词的时间段
//    NSMutableArray * tempTimeArr = [NSMutableArray arrayWithCapacity:1];
//    for (int i = 0; i < [array count]; i++) {
//        NSString *linStr = [array objectAtIndex:i];
//        //        NSLog(@"%@", linStr);
//        if (linStr.length<9 && linStr.length!=6) {
//            continue;
//        }
//        if ([linStr rangeOfString:@"]"].length == 0) {
//            continue;
//        }
//        
//        NSArray *lineArray = [linStr componentsSeparatedByString:@"]"];
//        //        for (NSString * gecistr in lineArray) {
//        //            NSLog(@"%@ ====%zd", gecistr, gecistr.length);
//        //            if (gecistr.length==2 && [gecistr isEqualToString:@"  "]) {
//        //                NSLog(@"空行");
//        //            }
//        //        }
//        
//        
//#pragma ---选择4的位置会有一些特殊的歌词有BUG---
//        //            if (i >= 1) {
//        NSString * lrcStr = [lineArray objectAtIndex:1];
//        NSString * timeStr = [lineArray objectAtIndex:0];
//        NSArray * intTime = [timeStr componentsSeparatedByString:@"."];
//        [self.timeArray addObject:[intTime objectAtIndex:0]];
//        // ----(歌词重复问题)----
//        if (lrcStr.length == 2 && [lrcStr isEqualToString:@"  "]) {
//            [self.LRCDictionary setObject:@"  " forKey:[intTime objectAtIndex:0]];
//        }else{
//            if (lrcStr.length == 0) {
//                [tempTimeArr addObject:[intTime objectAtIndex:0]];
//            }else{
//                [self.LRCDictionary setObject:lrcStr forKey:[intTime objectAtIndex:0]];
//                for (NSString * tempTimeStr in tempTimeArr) {
//                    [self.LRCDictionary setObject:lrcStr forKey:tempTimeStr];
//                }
//                [tempTimeArr removeAllObjects];
//            }
//        }
//        //            }
//        
//    }
//    
//    NSLog(@"%zd", self.timeArray.count);
//    
//    NSArray * tempTimeA = [NSArray arrayWithArray:self.timeArray];
//    tempTimeA = [tempTimeA sortedArrayUsingComparator:^NSComparisonResult(NSString* obj1, NSString* obj2) {
//        NSArray * timeArr1 = [obj1 componentsSeparatedByString:@":"];
//        NSInteger timeNumber1 = [[timeArr1 objectAtIndex:0] integerValue]*60 + [[timeArr1 objectAtIndex:1] integerValue];
//        NSArray * timeArr2 = [obj2 componentsSeparatedByString:@":"];
//        NSInteger timeNumber2 = [[timeArr2 objectAtIndex:0] integerValue]*60 + [[timeArr2 objectAtIndex:1] integerValue];
//        if (timeNumber1 > timeNumber2) {
//            return (NSComparisonResult)NSOrderedDescending;
//        }
//        if (timeNumber1 < timeNumber2) {
//            return (NSComparisonResult)NSOrderedAscending;
//        }
//        return (NSComparisonResult)NSOrderedSame;
//        
//    }];
//    [self.timeArray removeAllObjects];
//    [self.timeArray addObjectsFromArray:tempTimeA];
//    
//    [self LRCandGCD];
//}
//- (void)LRCandGCD
//{
//    JKSongsMessStatus * status = [self.songListArr objectAtIndex:_songIndex];
//    NSMutableArray * geciArray = [NSMutableArray arrayWithCapacity:1];
//    NSMutableDictionary * lrcDic = [NSMutableDictionary dictionaryWithCapacity:1];
//    [lrcDic setValuesForKeysWithDictionary:self.LRCDictionary];
//    NSMutableArray * timeArr = [NSMutableArray arrayWithCapacity:1];
//    [timeArr addObjectsFromArray:self.timeArray];
//    [geciArray addObject:lrcDic];
//    [geciArray addObject:timeArr];
//    [[TheHomeManager shareTheHomeManager].playGeCiDic setObject:geciArray forKey:[NSString stringWithFormat:@"%@", status.songID]];
//    [[TheHomeManager shareTheHomeManager] saveAllMusicAboutGeci];
//    
//    [self.geciTableView reloadData];
//    
//}

- (void)shareShengJingMessageWithImageArray:(NSArray *)imageArray title:(NSString *)title fuzhiStr:(NSString *)fuzhiStr
{
    NSLog(@"分享");
#pragma mark - 单接口分享
    if (imageArray) {
        
    }else{
        imageArray = @[[UIImage imageNamed:@"placeholder"]];
    }
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    
    [shareParams SSDKSetupShareParamsByText:fuzhiStr
                                     images:imageArray
                                        url:[NSURL URLWithString:_LCPlayer.playingSong.fileUrl]
                                      title:title
                                       type:SSDKContentTypeAudio];
    
    
    
    SSDKPlatformType typeNew = SSDKPlatformSubTypeWechatSession;
    [ShareSDK share:typeNew
         parameters:shareParams
     onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error)
     {
         switch (state) {
             case SSDKResponseStateSuccess:
             {
                 UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享成功"
                                                                     message:nil
                                                                    delegate:nil
                                                           cancelButtonTitle:@"确定"
                                                           otherButtonTitles:nil];
                 [alertView show];
                 break;
             }
             case SSDKResponseStateFail:
             {
                 UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享失败"
                                                                     message:[NSString stringWithFormat:@"%@", error]
                                                                    delegate:nil
                                                           cancelButtonTitle:@"确定"
                                                           otherButtonTitles:nil];
                 [alertView show];
                 break;
             }
//             case SSDKResponseStateCancel:
//             {
//                 UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享已取消"
//                                                                     message:nil
//                                                                    delegate:nil
//                                                           cancelButtonTitle:@"确定"
//                                                           otherButtonTitles:nil];
//                 [alertView show];
//                 break;
//             }
             default:
                 break;
         }
     }];
    
}

- (void)shengJingMessageCollectionWithTitle:(NSString *)title fuzhiStr:(NSString *)fuzhiStr{
    //            NSString * title = [NSString stringWithFormat:@"%@ %@", self.nameStr, self.zhangJieStr];
//                NSDictionary * dic = @{@"type":@"collectAdd", @"uid":[UserPageManager shareUserPageManager].userID, @"title":title, @"content":self.fuzhiStr};
    NSString * uid  = [NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults]objectForKey:@"uid"]];
    NSDictionary * dic = @{@"type":@"collectAdd", @"uid":uid, @"title":title, @"content":fuzhiStr};
    
            [kNetworkTool POSTWithUrlStringNew:kBasePostFuyin parameters:dic success:^(NSDictionary *json) {
    
                    NSString * status = nil;
                    if ([[json objectForKey:@"status"] isKindOfClass:[NSNumber class]]) {
                        status = [[json objectForKey:@"status"] stringValue];
                    }
                    if ([[json objectForKey:@"status"] isKindOfClass:[NSString class]]) {
                        status = [json objectForKey:@"status"];
                    }
                    MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.view animated:YES];
                    hud.mode=MBProgressHUDModeText;//枚举类型不同的效果
    
                    if ([status isEqualToString:@"200"]) {
                        hud.label.text=@"收藏成功";
                    }
                    if ([status isEqualToString:@"400"]) {
                        hud.label.text=@"收藏失败";
                    }
                    [self performSelector:@selector(hiddenMBAction) withObject:nil afterDelay:1.0];
    
                } failure:^(NSError *error) {
                    
                }];

}

//隐藏提示
-(void)hiddenMBAction
{
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}

@end
